﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using web.data.entities;
using web.bussines;
using Webdiyer.WebControls.Mvc;
using System.Web.UI;
using web.core.Controllers;

namespace web.core.Models
{
    public class articleModels
    {
        #region article_category
        public static void updateStatusArticleCategory(article_category cate)
        {
            article_service artSvc = new article_service();
            artSvc.updateStatusArticleCategory(cate);
        }

        public static int createArticleCategory(article_category cate,List<article_category_item> items)
        {
            article_service artSvc = new article_service();
            return artSvc.createArticleCategory(cate,items);
        }

        public static void deleteArticleCategory(int category_id)
        {
            article_service artSvc = new article_service();
            artSvc.deleteArticleCategory(category_id);
        }

        public static List<web.data.entities.article_category_item> GetListArticleCategoryItemsByCateID(int category_id, int? languageId)
        {
            article_service artSvc = new article_service();
            return artSvc.GetListArticleCategoryItemsByCateID(category_id, languageId);
        }

        public static web.data.entities.article_category GetArticleCategoryByID(int category_id)
        {
            article_service artSvc = new article_service();
            return artSvc.GetArticleCategoryByID(category_id);
        }

        public static void editArticleCategory(article_category cate, List<article_category_item> items)
        {
            article_service artSvc = new article_service();
            artSvc.editArticleCategory(cate,items);
        }

        #endregion

        #region v_category_article
        public static List<v_category_article> GetListCategoryArticleByParentAdm(int? cateId, int? languageId)
        {
            article_service artSvc = new article_service();
            return artSvc.GetListCategoryArticleByParentAdm(cateId, languageId);
        }

        public static List<v_category_article> getArticleCategoryBuilder(string text_search, int? parent, int? languageId)
        {
            article_service artSvc = new article_service();
            return artSvc.getCategoryArticleBuilder(text_search, parent, languageId);
        }

        public static List<v_category_article> getListCategoryArticleDropDownlist(int? id, int? languageId)
        {
            article_service artSvc = new article_service();
            return artSvc.getListCategoryArticleDropDownlist(id, languageId);
        }

        // lay thong tin theo id
        public static web.data.entities.v_category_article GetViewArticleCategoryByID(int category_id, int? languageId)
        {
            article_service artSvc = new article_service();
            return artSvc.GetViewArticleCategoryByID(category_id, languageId);
        }
        #endregion

        #region article
        public static void updateStatusArticle(article art)
        {
            article_service artSvc = new article_service();
            artSvc.updateStatusArticle(art);
        }

        public static int createArticle(article art, List<article_item> items, List<article_ref_category> list_ref)
        {
            article_service artSvc = new article_service();
            return artSvc.createArticle(art, items, list_ref);
        }

        public static List<web.data.entities.article_item> GetListArticleItemsByArticleID(int article_id, int? languageId)
        {
            article_service artSvc = new article_service();
            return artSvc.GetListArticleItemsByArticleID(article_id, languageId);
        }

        public static web.data.entities.article GetArticleByID(int article_id)
        {
            article_service artSvc = new article_service();
            return artSvc.GetArticleByID(article_id);
        }

        public static List<int> GetListCategoryByArticleID(int article_id)
        {
            article_service artSvc = new article_service();
            return artSvc.GetListCategoryByArticleID(article_id);
        }

        public static void DeleteAllArticleRefByArticleID(int article_id)
        {
            article_service artSvc = new article_service();
            artSvc.DeleteAllArticleRefByArticleID(article_id);
        }

        public static void editArticle(article art, List<article_item> items, List<article_ref_category> list_ref)
        {
            article_service artSvc = new article_service();
            artSvc.editArticle(art, items, list_ref);
        }

        public static void deleteArticle(int article_id)
        {
            article_service artSvc = new article_service();
            //xoa anh sp 
            var item = artSvc.GetArticleByID(article_id);
            if (item != null)
            {
                if (!string.IsNullOrEmpty(item.images))
                    baseController.DeleteFile(item.images);
            }
            //xoa db
            artSvc.deleteArticle(article_id);
        }

        public static void deleteArticleItem(int article_id, int languageid)
        {
            article_service artSvc = new article_service();
            artSvc.deleteArticleItem(article_id, languageid);
        }

        #endregion

        #region v_article
        //page list theo cate id
        public static PagedList<v_article> GetListArticleByCategoryID(int? languageId, int? cateId, int pageindex, int pagesite, string orderBy, string orderType, out int total)
        {
            article_service artSvc = new article_service();
            return artSvc.GetListArticleByCategoryID(languageId, cateId, pageindex, pagesite, orderBy, orderType, out total);
        } 
        // lay theo id
        public static v_article GetArticleViewByID(int article_id, int? languageId)
        {
            article_service artSvc = new article_service();
            return artSvc.GetArticleViewByID(article_id, languageId);
        }

        //lay tin cung danh muc
        public static List<v_article> ListOtherInCategory(int? languageId, int? cateId, int articleId, int take_number)
        {
             article_service artSvc = new article_service();
             return artSvc.ListOtherInCategory(languageId, cateId, articleId, take_number);
        }

        //lay danh sach nhung Tin lien quan 
        public static List<v_article> GetListArticleRelated(int articleId, int numberPost)
        {
             article_service artSvc = new article_service();
             return artSvc.GetListArticleRelated(articleId, numberPost);
        }
        //lay danh sach nhung tin ko lien quan 
        public static PagedList<v_article> GetListArticleNotRelate(int articleId, string text_search, int? languageId, int? cateId, int pageindex, int pagesite)
        {
            article_service artSvc = new article_service();
            return artSvc.GetListArticleNotRelate(articleId, text_search, languageId, cateId, pageindex, pagesite);
        }
        #endregion

        #region article relate
        public static bool article_relate_add(article_relate item)
        {
            article_service artSvc = new article_service();
            return artSvc.article_relate_add(item);
        } 

        public static bool article_relate_delete(int pid_a, int pid_b)
        {
            article_service artSvc = new article_service();
            return artSvc.article_relate_delete(pid_a, pid_b);
        }
        #endregion
    }
}